package com.zt.bigdata.flink.stream

import org.apache.flink.streaming.api.scala._

/**
  * 三种方式实现word count
  */
object WordStream {

  def main(args: Array[String]) {

    import org.apache.flink.api.java.utils.ParameterTool
    val parameters = ParameterTool.fromArgs(args)
    val host = parameters.get("host")
    val port = parameters.getInt("port")

    val env =
      StreamExecutionEnvironment.getExecutionEnvironment
    env.getConfig.setGlobalJobParameters(parameters)
    val text = env.socketTextStream(host, port)
    text.flatMap {
      _.toLowerCase.split("\\W+") filter (_.nonEmpty)
    }
      .map(_.toUpperCase)
      .addSink(x => println(x))


    env.execute("Window Stream WordStream")
  }

}
